package com.zhouxiaoge.队列.PriorityBlockingQueue;

import java.util.Comparator;
import java.util.concurrent.PriorityBlockingQueue;

/**
 * @author 周小哥  gqzmy@163.com 2022/11/18 21:08
 */

public class PriorityBlockingQueueTest {
    public static void main(String[] args) {
        Comparator<Person> comparing = Comparator.comparing(Person::getName);
        PriorityBlockingQueue<Person> priorityBlockingQueue = new PriorityBlockingQueue<>(11, comparing);
        getPriorityBlockingQueue(priorityBlockingQueue);
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        PriorityBlockingQueue<Person> queue = new PriorityBlockingQueue<>();
        getPriorityBlockingQueue(queue);
    }

    private static void getPriorityBlockingQueue(PriorityBlockingQueue<Person> queue) {
        queue.add(new Person(1, "D"));
        queue.add(new Person(4, "A"));
        queue.add(new Person(2, "C"));
        queue.add(new Person(3, "B"));
        queue.add(new Person(0, "E"));
        while (true) {
            Person poll = queue.poll();
            if (poll == null) {
                break;
            }
            System.out.println(poll);
        }
    }
}
